var pageii = null;
var grid = null;
$(function() {
	var roleId= $("#roleId").val();
	//alert(roleId)
	grid = lyGrid({
		id : 'paging',
		l_column : [ {
			colkey : "user_id",
			name : "id",
			width : "50px",
			hide : true
		}, {
			colkey : "user_name",
			name : "姓名"
		}, {
			colkey : "user_account",
			name : "账号",
		}, ],
		jsonUrl : rootPath + '/system/roleInfo/findUserByPage.shtml?role_id='+roleId,
		checkbox : true,
		serNumber : true,
		checkValue:'user_id',
		pageSize:10,
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		grid.setOptions({
			data : searchParams
		});
	});
	
	

	$("#addBtn").click(function() {
		var roleId= $("#roleId").val();
		window.location.href = ( rootPath + "/system/roleInfo/userList.shtml?roleId="+roleId);
		//showModal("user_add","关联用户", rootPath + "/roleInfo/userList.shtml?roleId="+roleId,880,650);
	});
	
	$("#delBtn").click( function() {
		var roleId= $("#roleId").val();
		var cbox = grid.getSelectedCheckbox();
		if (cbox == "") {
			tips("请选择需要删除的项",1);
			return;
		}
		confirm('你确定要删除该用户的角色吗？', function() {
			var url = rootPath + '/system/roleInfo/deleteUserRole.shtml?role_id='+roleId;
			var s = CommnUtil.ajax(url, {
				userIds : cbox.join(",")
			}, "json");
			if(s=="success"){
				tips("删除成功",1);
				loadData();
			}else{
				tips("删除失败",1);
			}
		});
	});
	
});


//重新加载数据
function loadData(){
	var searchParams = $("#searchForm").serializeJson();// 初始化传参数
	grid.setOptions({
		data : searchParams
	});
}


function tips(title,time){
	time = time?time:3;
	 Wind.use("artDialog", "iframeTools", function () {
	        art.dialog.tips(title).time(time);
	 });
}

function confirm(title,yes,no){
	 Wind.use("artDialog", "iframeTools", function () {
		art.dialog.confirm(title, function () {
			if(yes){
				yes()
			}
		}, function () {
			if(no){
				no()
			}
		});
	 });
}




function showModal(id,title, url,width,height) {
    Wind.use("artDialog", "iframeTools", function () {
        art.dialog.open(url, {
            title: title,
            id: id,
            width: width,
            height: height,
            lock: true,
            fixed: true,
            background: "#CCCCCC",
            opacity: 0.7
        });
    });
}
